package com.i2works.smartluolong.manageapi.controller.common;

import com.google.common.collect.Lists;
import com.i2works.smartluolong.utils.base.AppConstant;
import com.i2works.smartluolong.utils.common.SmsUtil;
import com.i2works.smartluolong.utils.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短信
 *
 * @author Liu Yutao <koal@vip.qq.com>
 * @date 2018/1/29 16:52
 */
@RestController
@RequestMapping("/common/sms")
public class SmsController {

    private final SmsUtil smsUtil;

    @Autowired
    public SmsController(SmsUtil smsUtil) {
        this.smsUtil = smsUtil;
    }

    /**
     * 发送通知短信
     *
     * @param phone       手机号码
     * @param placeHolder 短信目标里的占位符
     */
    @PostMapping("/notify")
    public Result notify(@RequestParam(value = "phone") String phone, @RequestParam(value = "placeHolder") String placeHolder) {
        return smsUtil.notify(AppConstant.ALIYUN_SMS_TEMPLATECODE, placeHolder, Lists.newArrayList(phone));
    }

}
